cap log close
log using ${log}\02_merge_BHP.log, replace


/*
	~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
	
	SIAB Preparation
	
	Merge the Establishment History Panel (BHP) to the SIAB	
	
	Author(s): Wolfgang Dauth, Johann Eppelsheimer
	
	Version: 1.0
	Created: 2018-06-01
	
	~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
*/



********************************************************************************
* Save original begin and end date of episodes
********************************************************************************

* merge BHP

forvalues jahr = 2017/2017 {
    
preserve 

use $fileBHP/bhp_7519_m06_v2_`jahr'.dta, clear 

tempfile bhp`jahr'
gen jahr = `jahr'

save `bhp`jahr''

restore

merge m:1 betnr jahr using `bhp`jahr'', gen(_bhp`jahr') keepusing(betnr grd_dat lzt_dat az_ges az_f az_gq az_mq az_hq az_d alter_mw az_vz az_tz az_f_vz az_f_tz) update

drop if _bhp`jahr' == 2

*tab erwstat _merge  // not matched individuals are in almost all cases non-workers
*drop _merge



}


* change language of labels
label language en


cap log close
